<!DOCTYPE html>
<html>
	<head>
		<script src="js/jquery.min.js"></script>
		<meta charset="utf-8">
		<title>初体验AJAX</title>
		<style type="text/css">
			div{
				font-size: 30px;
				margin-top: 30px;
			}
		</style>
	</head>
	<body>
		<div id="">
			<label>请输入商品ID：</label>
			<input type="text" name="ItemID" id="itemID"/>
		</div>
		<div id="">
			<button type="button" class="mui-btn mui-btn-blue" onclick="method()">确定</button>
		</div>
		<div><span id="ID"></span></div>
		<div><span id="itemPrice"></span></div>
	</body>
	
	<script type="text/javascript">
		//jquery提供的AJAX
		function method(){
			var item=$("#itemID").val();
			$.ajax({
				type:"POST",//发起POST请求
				url:"https://p.3.cn/prices/mgets?skuIds=J_"+item,
				//data也是js对象
				data:{"skuIds":"J_100009077459"},
				contentType:"application/json;charset=utf-8",
				dataType:"jsonp",
				success:function(data){
					console.log("访问成功");
					console.log(data);
					$("#ID").text("编号："+data[0].id);
					$("#itemPrice").text("价格："+data[0].p+"元");
					console.log(data[0].id);
					console.log(data[0].p);
				},
				error:function(e){
					console.log("访问失败");
				}
			});
		}
	</script>
</html>
